package com.atguigu.gmall.order.config;

import com.atguigu.gmall.rabbit.constant.MqConst;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class DelayMqConfig {
    //交换机   交换机内延迟
    //routingKey
    //队列

    @Bean
    public Exchange exchange1(){
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type","direct");
        return new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL,"x-delayed-message",true,false,args);
    }

    @Bean
    public Queue queue1(){
        return QueueBuilder.durable(MqConst.QUEUE_ORDER_CANCEL).build();
    }

    @Bean
    //qualifier 取自IOC容器，死信中取自当前，一般使用容器中取队列和交换机
    public Binding binding(@Qualifier(value = "queue1") Queue queue,@Qualifier(value = "exchange1") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }

}
